#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1010;

int n, m, k, l, d;
struct node
{
	int pos, t;
}a[N], b[N];

bool cmp1(node& n1, node& n2)
{
	return n1.t > n2.t;
}

bool cmp2(node& n1, node& n2)
{
	return n1.pos < n2.pos;
}

int main()
{
	cin >> m >> n >> k >> l >> d;
	for(int i = 1;i <= m;i ++) a[i].pos = i;
	for(int i = 1;i <= n;i ++) b[i].pos = i;
	while(d --)
	{
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		if(y1 == y2) a[min(x1, x2)].t ++;
		else b[min(y1, y2)].t ++;
	}
	sort(a + 1, a + 1 + m, cmp1);
	sort(b + 1, b + 1 + n, cmp1);

	sort(a + 1, a + 1 + k, cmp2);
	sort(b + 1, b + 1 + l, cmp2);
	for(int i = 1;i <= k;i ++) cout << a[i].pos << " ";
	cout << endl;
	for(int i = 1;i <= l;i ++) cout << b[i].pos << " ";
	return 0;
}